//do /Users/shoude/Dropbox/eegap/EEgap_data_code_heter_SM/Code/UMD_Survey_EnergyLit.do

pause on
 
*global  UMDdatapath = "\\c3\rdat\SHoude\Research\EEgap\FIRE 2017 Fall"
*global pathname="\\c3\rdat\SHoude\Research\sears\estar_data"
*global censuspath="\\c3\rdat\SHoude\Research\data_all\census"


global UMDdatapath = "/Users/shoude/Dropbox/eegap/EEgap_data_code_heter_SM/Data/UMD_survey"
global pathname     = "/Users/shoude/Dropbox/eegap/EEgap_data_code_heter_SM/Data"
global censuspath   = "/Users/shoude/Dropbox/eegap/EEgap_data_code_heter_SM/Data"


/*
Important questions
v19: income
v27: zipcode
v32: home ownership
v40: cents/kWh
v41: kWh/y refrigerator
v44: ES certification requirement
v46: Summer month kWh/month
v76: pid
*/


/*
//Generate file to merge pair_id kwh 
use $pathname\refrigerators\pairs_matched_2_size2only_manual_check_YQ_SH_day_zip_size2only_reg_ready, clear

collapse(firstnm) kwh,by(pid pid_pair_2)
keep if kwh != .
sort pid_pair_2 kwh
by pid_pair_2: egen pair_ee = seq() 
drop pid
reshape wide kwh,i(pid_pair_2) j(pair_ee)

rename  pid_pair_2 pid_pair_id
sort pid_pair_id

save $pathname\refrigerators\pairs_id_kwh_only_wide, replace
*/

insheet using "$UMDdatapath/UMD_Survey_Raw.csv", clear

pause

keep v19 v26 v27 v32 v40 v41 v44 v46 v47 v76 
rename v19 income 
rename v26 state_name
rename v27 zipcode 
rename v32 home_own 
rename v40 belief_price_elec 
rename v41 belief_fridge_elec 
rename v44 belief_ES 
rename v46 belief_summer 
rename v47 last_purc_app
rename v76 pid


destring zipcode, replace force

sort zipcode
		*merge zipcode using $censuspath\mapping_zip_county_nov99_short
		merge zipcode using $censuspath/mapping_zip_county_nov99
		tab _m
		drop if _m==2
		drop _m
		ren county5 county_utility
		
gen year=2012		
sort county_utility year
		//merge county_utility year using "$pathname\electricity\county_price_tmp"  
		merge county_utility year using $pathname/county_elec_price_2007_2012
  		tab _m
  		drop if _m==2
  		drop _m
  		//replace pcount=p_elec if pcount==. 
  		
tab belief_price_elec 

pause

replace belief_price_elec="7" if belief_price_elec=="$0.07"     
replace belief_price_elec="8" if belief_price_elec=="$0.08"     
replace belief_price_elec="10" if belief_price_elec=="$0.10"        
replace belief_price_elec="11" if belief_price_elec=="$0.11"     
replace belief_price_elec="23" if belief_price_elec=="$0.23"     
replace belief_price_elec="37" if belief_price_elec=="$0.37"     
replace belief_price_elec="72" if belief_price_elec=="$0.72/kWh" 
replace belief_price_elec="99" if belief_price_elec=="$0.99"     
replace belief_price_elec="1000" if belief_price_elec=="$1,000"    
replace belief_price_elec="100" if belief_price_elec=="$100"      
replace belief_price_elec="2" if belief_price_elec=="$2"               
replace belief_price_elec="200" if belief_price_elec=="$200"      
replace belief_price_elec="220" if belief_price_elec=="$220"      
replace belief_price_elec="3" if belief_price_elec=="$3"        
replace belief_price_elec="40" if belief_price_elec=="$40"       
replace belief_price_elec="5" if belief_price_elec=="$5"        
replace belief_price_elec="50" if belief_price_elec=="$50"       
replace belief_price_elec="12" if belief_price_elec==". 12"      
replace belief_price_elec="50" if belief_price_elec=="..50"      
replace belief_price_elec="10" if belief_price_elec==".10/kWh"   
replace belief_price_elec="13" if belief_price_elec==".13/kWh"   
replace belief_price_elec="30" if belief_price_elec==".30$"      
replace belief_price_elec="10" if belief_price_elec=="10 cents"                           
replace belief_price_elec="10.1" if belief_price_elec=="10.I cents"       
replace belief_price_elec="10" if belief_price_elec=="10/kWh"           
replace belief_price_elec="100" if belief_price_elec=="100$"
replace belief_price_elec="10" if belief_price_elec=="10cents per kilowatt"
replace belief_price_elec="11" if belief_price_elec=="11cent"   
replace belief_price_elec="12" if belief_price_elec=="12 cents"
replace belief_price_elec="12" if belief_price_elec=="12/kWh"
replace belief_price_elec="13" if belief_price_elec=="13 cents"
replace belief_price_elec="13.1" if belief_price_elec=="13.1 cents per kwh"
replace belief_price_elec="13" if belief_price_elec=="13¢/kWh"
replace belief_price_elec="14" if belief_price_elec=="14 cents"
replace belief_price_elec="14.46" if belief_price_elec=="14.46 cents"
replace belief_price_elec="15" if belief_price_elec=="15 cents"
replace belief_price_elec="17" if belief_price_elec=="17 cents."
replace belief_price_elec="18" if belief_price_elec=="18/kWh"
replace belief_price_elec="20" if belief_price_elec=="20/kWh"
replace belief_price_elec="20" if belief_price_elec=="20c/kWh"
replace belief_price_elec="22" if belief_price_elec=="22 cents per kWh"
replace belief_price_elec="25" if belief_price_elec=="25 cents"
replace belief_price_elec="250" if belief_price_elec=="250 a month"
replace belief_price_elec="253" if belief_price_elec=="253 kWh"
replace belief_price_elec="2" if belief_price_elec=="2¢/KWh"
replace belief_price_elec="3" if belief_price_elec=="3 cents"
replace belief_price_elec="3" if belief_price_elec=="3$"
replace belief_price_elec="30" if belief_price_elec=="30/kwh"
replace belief_price_elec="30" if belief_price_elec=="30¢/kWh"
replace belief_price_elec="35" if belief_price_elec=="35 cents"
replace belief_price_elec="36" if belief_price_elec=="36/100"
replace belief_price_elec="4" if belief_price_elec=="4 c"
replace belief_price_elec="4.5" if belief_price_elec=="4.5   this is a total guess"
replace belief_price_elec="40" if belief_price_elec=="40 cents"
replace belief_price_elec="5" if belief_price_elec=="5 cents"
replace belief_price_elec="5" if belief_price_elec=="5/kwh"
replace belief_price_elec="50" if belief_price_elec=="50 cents"
replace belief_price_elec="6" if belief_price_elec=="6 cents/kwh"
replace belief_price_elec="6.5" if belief_price_elec=="6.5 cents"
replace belief_price_elec="30" if belief_price_elec=="60/200"
replace belief_price_elec="60" if belief_price_elec=="60¢/kWh"
replace belief_price_elec="65" if belief_price_elec=="65/kWh"
replace belief_price_elec="68" if belief_price_elec=="68/kwh"
replace belief_price_elec="7.7" if belief_price_elec=="7.7 cents"
replace belief_price_elec="75" if belief_price_elec=="75. Cents"
replace belief_price_elec="8" if belief_price_elec=="8 cents"
replace belief_price_elec="88" if belief_price_elec=="88/kWh"
replace belief_price_elec="9" if belief_price_elec=="9 cents"
replace belief_price_elec="9" if belief_price_elec=="9 down to 7 cents over 500"
replace belief_price_elec="90" if belief_price_elec=="90/kWh"
replace belief_price_elec="9" if belief_price_elec=="9cents"

pause

gen recent_pur=0
replace  recent_pur=1 if last_purc_app=="More than 1 year ago but within the past 3 years"
replace  recent_pur=1 if last_purc_app=="Less than 6 months ago"

destring belief_price_elec, gen(belief_price_elec_num) force
replace belief_price_elec_num =belief_price_elec_num*100 if belief_price_elec_num<1
gen belief_price_pct_bias= 100*(belief_price_elec_num- pcounty_elec)/ pcounty_elec
gen belief_price_m_bias= belief_price_elec_num/ pcounty_elec
sum belief_price_m_bias if belief_price_m_bias<100
sum belief_price_m_bias if belief_price_m_bias<10

gen belief_price_m_bias_cens=belief_price_m_bias
replace belief_price_m_bias_cens=5 if  belief_price_m_bias>5
sum belief_price_m_bias_cens
local m_price=r(mean)
hist belief_price_m_bias_cens if belief_price_m_bias_cens>0, xline(`m_price',lcolor(red) lwidth(thick)) lcolor(black) title(,) ytitle("Density", size(medlarge)) xtitle("Misperception: m",height(5) size(medlarge)) ylabel(, nogrid labsize(medlarge)) xlabel(0(1)5, nogrid labsize(medlarge)) graphregion(fcolor(white) ifcolor(white) icolor(white) lcolor(white))  legend( off )         fcolor(white) 
graph export "/Users/shoude/Dropbox/eegap/EEgap_data_code_heter_SM/Results_FigurePaper/hist_UMD_belief_price.eps", as(eps) preview(off) replace
graph export "/Users/shoude/Dropbox/eegap/EEgap_data_code_heter_SM/Results_FigurePaper/hist_UMD_belief_price.pdf", as(pdf) replace

hist belief_price_m_bias_cens if belief_price_m_bias_cens>0,by(recent_pur) xline(`m_price',lcolor(red) lwidth(thick)) lcolor(black) title(,) ytitle("Density", size(medlarge)) xtitle("Misperception: m",height(5) size(medlarge)) ylabel(, nogrid labsize(medlarge)) xlabel(0(1)5, nogrid labsize(medlarge)) graphregion(fcolor(white) ifcolor(white) icolor(white) lcolor(white))  legend( off )         fcolor(white) 

pause



destring belief_fridge_elec, gen(belief_fridge_elec_num) force
gen belief_fridge_m_bias= belief_fridge_elec_num/ 450
sum belief_fridge_m_bias if belief_fridge_m_bias<10  & belief_fridge_m_bias>0

gen belief_fridge_m_bias_cens=belief_fridge_m_bias
replace belief_fridge_m_bias_cens=5 if  belief_fridge_m_bias>5
sum belief_fridge_m_bias_cens
local m_usage=r(mean)
hist belief_fridge_m_bias_cens if belief_fridge_m_bias_cens>0, xline(`m_usage',lcolor(red) lwidth(thick)) lcolor(black) title(,) ytitle("Density", size(medlarge)) xtitle("Misperception: m",height(5) size(medlarge)) ylabel(, nogrid labsize(medlarge)) xlabel(0(1)5, nogrid labsize(medlarge)) graphregion(fcolor(white) ifcolor(white) icolor(white) lcolor(white))  legend( off )         fcolor(white) 
graph export "/Users/shoude/Dropbox/eegap/EEgap_data_code_heter_SM/Results_FigurePaper/hist_UMD_belief_usage.eps", as(eps) preview(off) replace
graph export "/Users/shoude/Dropbox/eegap/EEgap_data_code_heter_SM/Results_FigurePaper/hist_UMD_belief_usage.pdf", as(pdf) replace


hist belief_fridge_m_bias_cens if belief_fridge_m_bias_cens>0,by(recent_pur) xline(`m_usage',lcolor(red) lwidth(thick)) lcolor(black) title(,) ytitle("Density", size(medlarge)) xtitle("Misperception: m",height(5) size(medlarge)) ylabel(, nogrid labsize(medlarge)) xlabel(0(1)5, nogrid labsize(medlarge)) graphregion(fcolor(white) ifcolor(white) icolor(white) lcolor(white))  legend( off )         fcolor(white) 

pause

gen belief_annual_cost=belief_price_elec_num*belief_fridge_elec_num
gen annual_cost=450*pcounty_elec
gen belief_annual_cost_m_bias= belief_annual_cost/ annual_cost
sum belief_annual_cost_m_bias if belief_annual_cost_m_bias<10  & belief_annual_cost_m_bias>0

gen belief_annual_cost_m_bias_cens=belief_annual_cost_m_bias
replace belief_annual_cost_m_bias_cens=5 if  belief_annual_cost_m_bias>5
sum belief_annual_cost_m_bias_cens
local m_cost=r(mean)
hist belief_annual_cost_m_bias_cens if belief_annual_cost_m_bias_cens>0, xline(`m_cost',lcolor(red) lwidth(thick)) lcolor(black) title(,) ytitle("Density", size(medlarge)) xtitle("Misperception: m",height(5) size(medlarge)) ylabel(, nogrid labsize(medlarge)) xlabel(0(1)5, nogrid labsize(medlarge)) graphregion(fcolor(white) ifcolor(white) icolor(white) lcolor(white))  legend( off )         fcolor(white) 
graph export "/Users/shoude/Dropbox/eegap/EEgap_data_code_heter_SM/Results_FigurePaper/hist_UMD_belief_cost.eps", as(eps) preview(off) replace
graph export "/Users/shoude/Dropbox/eegap/EEgap_data_code_heter_SM/Results_FigurePaper/hist_UMD_belief_cost.pdf", as(pdf) replace

tab belief_ES
gen belief_ES_tmp=substr(belief_ES,1,2)
destring belief_ES_tmp, gen(belief_ES_num) force
gen belief_ES_m_bias= belief_ES_num/ 10
sum belief_ES_m_bias if belief_ES_m_bias<10  & belief_ES_m_bias>0

gen belief_ES_m_bias_cens=belief_ES_m_bias
replace belief_ES_m_bias_cens=5 if  belief_ES_m_bias>5
sum belief_ES_m_bias_cens
local m_ES=r(mean)
hist belief_ES_m_bias_cens if belief_ES_m_bias_cens>0, xline(`m_ES',lcolor(red) lwidth(thick)) lcolor(black) title(,) ytitle("Density", size(medlarge)) xtitle("Misperception: m",height(5) size(medlarge)) ylabel(, nogrid labsize(medlarge)) xlabel(0(1)5, nogrid labsize(medlarge)) graphregion(fcolor(white) ifcolor(white) icolor(white) lcolor(white))  legend( off )         fcolor(white) 
graph export "/Users/shoude/Dropbox/eegap/EEgap_data_code_heter_SM/Results_FigurePaper/hist_UMD_belief_ES.eps", as(eps) preview(off) replace
graph export "/Users/shoude/Dropbox/eegap/EEgap_data_code_heter_SM/Results_FigurePaper/hist_UMD_belief_ES.pdf", as(pdf) replace


tab state_name if state!=.


                 